<?php $this->headTitle('Credit Purchases');  ?>
<?php $this->headScript()->appendFile('js/jquery/jquery.form.js'); ?>
<script type="text/javascript">
$(function(){

$('#searchBtn').click(function(event){

	var qstrring;

		      if($.trim($('#search').val()) == ""){
			      alert('Please enter a search keyword');
			      $('#search').focus();
			      return false;
		      }
	    	  qstrring = $('#search').fieldSerialize(false);

	window.location = "<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true); ?>" + "?" + qstrring;
	return false;
});


});
</script>
<script type="text/javascript"><!--
$(function(){
$('#search').keydown(function(e) {
		if (e.keyCode == 13) {
			$('#searchBtn').click();
		}
	});
});
//--></script>

<?php if(!empty($this->returnMessageSuccess)): ?>
<div class="success"><?php echo $this->escape($this->returnMessageSuccess[0]); ?></div>
<?php endif; ?>

<?php if(!empty($this->returnMessageWarning)): ?>
<div class="warning"><?php echo $this->escape($this->returnMessageWarning[0]); ?></div>
<?php endif; ?>

<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
    <h1 style="background-image: url('images/product.png');">Credit Purchases</h1>
    <div class="buttons">
    <a onclick="location = '<?php echo $this->url(array('do'=>'insert'),'inventoryCredit',true); ?>'" class="button"><span>Insert</span></a>
    <a class="button" id="delete"><span>Delete</span></a>
    </div>
  </div>
  <div class="content">

    <table style="width: 100%" border="0" cellspacing="0" cellpadding="0" class="filter">
	<tr>
		<td style="width:20px">&nbsp;</td>
		<td class="right" style="width:50px">
                    <input type="text" name="search" id="search" value="" class="search-box">
                </td>
		<td style="width:20px">&nbsp;</td>
		<td class="left"><a class="button" id="searchBtn"><span>Search</span></a></td>
	</tr>
	</table>

	 <form action="<?php echo $this->url(array('do'=>'delete'),'inventoryCredit',true); ?>" method="post" enctype="multipart/form-data" id="form">
      <input type="hidden" name="redir" value="<?php echo $this->requestUri(); ?>">
      <table class="list">
        <thead>
          <tr>
            <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
            <td class="left">
                <?php if((isset($this->data['sort'])) && ($this->data['sort'] == 'product')): ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=product". $this->partHeadUrl; ?>" class="<?php echo strtolower($this->data['order']); ?>">Product</a>
                <?php else: ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=product". $this->partHeadUrl; ?>">Product</a>
                <?php endif; ?>
            </td>
            <td class="left">
                <?php if((isset($this->data['sort'])) && ($this->data['sort'] == 'quantity')): ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=quantity". $this->partHeadUrl; ?>" class="<?php echo strtolower($this->data['order']); ?>">Quantity</a>
                <?php else: ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=quantity". $this->partHeadUrl; ?>">Quantity</a>
                <?php endif; ?>
            </td>
            <td class="left">
                <?php if((isset($this->data['sort'])) && ($this->data['sort'] == 'price')): ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=price". $this->partHeadUrl; ?>" class="<?php echo strtolower($this->data['order']); ?>">Price</a>
                <?php else: ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=price". $this->partHeadUrl; ?>">Price</a>
                <?php endif; ?>
            </td>
            <td class="right">
                <?php if((isset($this->data['sort'])) && ($this->data['sort'] == 'supplier')): ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=supplier". $this->partHeadUrl; ?>" class="<?php echo strtolower($this->data['order']); ?>">Supplier</a>
                <?php else: ?>
                <a href="<?php echo $this->url(array('do'=>'access'),'inventoryCredit',true). "?sort=supplier". $this->partHeadUrl; ?>">Supplier</a>
                <?php endif; ?>
            </td>
            <td class="right">Action</td>
          </tr>
        </thead>
        <tbody>
            <?php if($this->inventories): ?>
                    <?php foreach($this->inventories as $inventory): ?>
                      <tr>
                        <td style="text-align: center;"><input type="checkbox" name="selected[]" value="<?php echo $inventory->entryId; ?>" /></td>
                        <td class="left"><?php echo $this->escape($inventory->product); ?></td>
                        <td class="left"><?php echo $inventory->quantity; ?></td>
                        <td class="left"><?php echo $inventory->price; ?></td>
                        <td class="right"><?php echo $this->escape($inventory->supplier); ?></td>
                        <td class="right">[ <a href="<?php echo $this->url(array('do'=>'update','id'=>$inventory->entryId),'inventoryCredit',true)."?redir=".urlencode($this->requestUri()); ?>">View / Edit</a> ]</td>
                      </tr>
        <?php endforeach; ?>

	<?php else: ?>
          <tr>
            <td class="center" colspan="6">No results!</td>
          </tr>
       <?php endif; ?>
        </tbody>
      </table>
	 </form>
      <?php if($this->inventories instanceof Zend_Paginator):?>
          <?php echo $this->paginationControl(
                            $this->inventories,
                            'Sliding',
                            '_paginator.phtml',
                            array('url'=>$this->url(array('do'=>'access'),'inventoryCredit',true),
                                  'partUrl'=>$this->partPaginationUrl,
                            )
                            );
          ?>
      <?php endif ?>
  </div>
</div>